<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="12">
          <a-col :md="4" :sm="8">
            <a-form-item
              label="设备名称"
              :maxLength="50">
              <a-input placeholder="请输入名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="8">
            <a-form-item label="状态">
              <a-select v-model="queryParam.useState" placeholder="请选择">
                <a-select-option value="">请选择</a-select-option>
                <a-select-option
                  v-for="(item) in this.$sysDictOptions('useState')"
                  :key="item.k"
                  :value="item.k">
                  {{ item.v }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-item label="所在位置">
              <a-cascader
                      v-model="roomValue"
                      :options="optionsRoom"
                      @change="handleChange"
                      change-on-select
                      placeholder="请选择地址"
              />
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="$refs.table.refresh(true)" icon="search">查询</a-button>
              <a-button
                @click="() => {this.$objToReset(queryParam),this.roomValue=[],$refs.table.refresh(true)}"
                icon="reload"
                style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
      <div class="table-operator">
        <a-button @click="$refs.modalEdit.add(queryParam.equType)" type="primary" icon="plus" v-wx-role="30201">添加</a-button>
        <a-button type="primary" icon="upload" @click="$refs.fileEdit.edit()">导入</a-button>
        <a-button type="primary" icon="export" @click="">导出</a-button>
        <a-dropdown v-if="selectedRowKeys.length > 0">
          <a-menu slot="overlay">
            <a-menu-item>
              <a-popconfirm
                  title="确定删除吗?"
                  @confirm="() => handleDelete()"
                  v-wx-role="30204">
                <a><a-icon type="delete"/>删除</a>
              </a-popconfirm>
            </a-menu-item>
          </a-menu>
          <a-button style="margin-left: 8px">批量操作<a-icon type="down"/></a-button>
        </a-dropdown>
      </div>
      <s-table
        ref="table"
        rowKey="id"
        size="middle"
        :scroll="{ x: 1200,y:610 }"
        :columns="columns"
        :alert="options.alert"
        :customRow="rowClick"
        :data="loadData">
        <template slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-wx-role="30202">
            <a-icon type="edit"/>编辑</a>
          <a-divider type="vertical"/>
          <a @click="handelView(record)" v-wx-role="30204"><a-icon/> 查看</a>
          <a-divider type="vertical"/>
          <a-popconfirm title="确定删除吗?" @confirm="() =>handleDelete(record.id)" v-wx-role="30203">
            <a>删除</a>
          </a-popconfirm>
        </template>
      </s-table>

      <equ-equipment-edit ref="modalEdit" @ok="modalEditOk"></equ-equipment-edit>
      <equ-equipment-view ref="modalView"></equ-equipment-view>
      <file-detail-upload ref="fileEdit" @ok="modalEditOk"></file-detail-upload>
    </div>
  </a-card>
</template>

<script>
  import { STable, Ellipsis } from '@/components'
  import { deleteAction, postAction,getAction } from '@/api/manage'
  import { mixin } from '@/utils/mixin'
  import EquEquipmentEdit from './EquEquipmentEdit'
  import EquEquipmentView from './EquEquipmentView'
  import FileDetailUpload from "./fileDetailUpload";

  export default {
    name: 'EquEquipmentList1',
      props:["typeid"],
    mixins: [mixin],
    components: {FileDetailUpload, STable, Ellipsis, EquEquipmentEdit, EquEquipmentView },
    data () {
      return {
        visible: false,
        // 查询条件
        queryParam: {
          title: ''
        },
        // 表头
        // 如果需要字典，那么需要在columns列中加入 customRender: (text) => this.$sysDictFilter(text, 'xxxx')xxxx 为dataIndex
        columns: [
          {
            title: '设备名称',
            dataIndex: 'name',
              width:200
          },
            {
                title: '设备小类',
                dataIndex: 'equType1'
            },
          {
            title: '型号',
            dataIndex: 'quality'
          },
            {
                title: '设备编号',
                dataIndex: 'equNo',
                width:150
            },
            {
                title: '设备原值',
                dataIndex: 'equvalue'
            },
          {
            title: '所在位置',
              width:300,
            dataIndex: 'addressS',
              customRender: (text,record) =>{
                var ads = record.campusAddress;
                if(record.buildings){
                    ads+="/"+record.buildings;
                }
                  if(record.floors){
                      ads+="/"+record.floors;
                  }
                  if(record.rooms){
                      ads+="/"+record.rooms;
                  }
                  if(record.address){
                      ads+=""+record.address;
                  }
                return ads
              }
          },
          {
            title: '启用日期',
            dataIndex: 'anzDate'
          },
          {
            title: '状态',
            dataIndex: 'useState'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
              width:220,
            fixed: 'right',
            scopedSlots: { customRender: 'action' }
          }
        ],
          columns0: [
              {
                  title: '设备名称',
                  dataIndex: 'name',
                  width:200
              },
              {
                  title: '设备小类',
                  dataIndex: 'equType1'
              },
              {
                  title: '型号',
                  dataIndex: 'quality'
              },
              {
                  title: '设备编号',
                  dataIndex: 'equNo',
                  width:150
              },
              {
                  title: '设备原值',
                  dataIndex: 'equvalue'
              },
              {
                  title: '所在位置',
                  width:300,
                  dataIndex: 'addressS',
                  customRender: (text,record) =>{
                      var ads = record.campusAddress;
                      if(record.buildings){
                          ads+="/"+record.buildings;
                      }
                      if(record.floors){
                          ads+="/"+record.floors;
                      }
                      if(record.rooms){
                          ads+="/"+record.rooms;
                      }
                      if(record.address){
                          ads+=""+record.address;
                      }
                      return ads
                  }
              },
              {
                  title: '启用日期',
                  dataIndex: 'anzDate'
              },
              {
                  title: '状态',
                  dataIndex: 'useState'
              },
              {
                  title: '操作',
                  dataIndex: 'action',
                  align: 'center',
                  width:220,
                  fixed: 'right',
                  scopedSlots: { customRender: 'action' }
              }
          ],
          columns1: [
              {
                  title: '设备名称',
                  dataIndex: 'name',
                  width:200
              },
              {
                  title: '设备小类',
                  dataIndex: 'equType1'
              },
              {
                  title: '型号',
                  dataIndex: 'quality'
              },
              {
                  title: '设备编号',
                  dataIndex: 'equNo',
                  width:150
              },
              {
                  title: '设备原值',
                  dataIndex: 'equvalue'
              },
              {
                  title: '所在位置',
                  width:300,
                  dataIndex: 'addressS',
                  customRender: (text,record) =>{
                      var ads = record.campusAddress;
                      if(record.buildings){
                          ads+="/"+record.buildings;
                      }
                      if(record.floors){
                          ads+="/"+record.floors;
                      }
                      if(record.rooms){
                          ads+="/"+record.rooms;
                      }
                      if(record.address){
                          ads+=""+record.address;
                      }
                      return ads
                  }
              },
              {
                  title: '启用日期',
                  dataIndex: 'anzDate'
              },
              {
                  title: '状态',
                  dataIndex: 'useState'
              },
              {
                  title: '操作',
                  dataIndex: 'action',
                  align: 'center',
                  width:220,
                  fixed: 'right',
                  scopedSlots: { customRender: 'action' }
              }
          ],
          columns2: [
              {
                  title: '设备名称',
                  dataIndex: 'name',
                  width:200
              },
              {
                  title: '设备小类',
                  dataIndex: 'equType1'
              },
              {
                  title: '型号',
                  dataIndex: 'quality'
              },
              {
                  title: '设备编号',
                  dataIndex: 'equNo',
                  width:150
              },
              {
                  title: '设备原值',
                  dataIndex: 'equvalue'
              },
              {
                  title: '所在位置',
                  width:300,
                  dataIndex: 'addressS',
                  customRender: (text,record) =>{
                      var ads = record.campusAddress;
                      if(record.buildings){
                          ads+="/"+record.buildings;
                      }
                      if(record.floors){
                          ads+="/"+record.floors;
                      }
                      if(record.rooms){
                          ads+="/"+record.rooms;
                      }
                      if(record.address){
                          ads+=""+record.address;
                      }
                      return ads
                  }
              },
              {
                  title: '启用日期',
                  dataIndex: 'anzDate'
              },
              {
                  title: '状态',
                  dataIndex: 'useState'
              },
              {
                  title: '操作',
                  dataIndex: 'action',
                  align: 'center',
                  width:220,
                  fixed: 'right',
                  scopedSlots: { customRender: 'action' }
              }
          ],
          columns3: [
              {
                  title: '设备名称',
                  dataIndex: 'name',
                  width:200
              },
              {
                  title: '设备小类',
                  dataIndex: 'equType1'
              },
              {
                  title: '型号',
                  dataIndex: 'quality'
              },
              {
                  title: '设备编号',
                  dataIndex: 'equNo',
                  width:150
              },
              {
                  title: '设备原值',
                  dataIndex: 'equvalue'
              },
              {
                  title: '所在位置',
                  width:300,
                  dataIndex: 'addressS',
                  customRender: (text,record) =>{
                      var ads = record.campusAddress;
                      if(record.buildings){
                          ads+="/"+record.buildings;
                      }
                      if(record.floors){
                          ads+="/"+record.floors;
                      }
                      if(record.rooms){
                          ads+="/"+record.rooms;
                      }
                      if(record.address){
                          ads+=""+record.address;
                      }
                      return ads
                  }
              },
              {
                  title: '启用日期',
                  dataIndex: 'anzDate'
              },
              {
                  title: '状态',
                  dataIndex: 'useState'
              },
              {
                  title: '操作',
                  dataIndex: 'action',
                  align: 'center',
                  width:220,
                  fixed: 'right',
                  scopedSlots: { customRender: 'action' }
              }
          ],
          columns4: [
              {
                  title: '设备名称',
                  dataIndex: 'name',
                  width:200
              },
              {
                  title: '设备小类',
                  dataIndex: 'equType1'
              },
              {
                  title: '型号',
                  dataIndex: 'quality'
              },
              {
                  title: '设备编号',
                  dataIndex: 'equNo',
                  width:150
              },
              {
                  title: '设备原值',
                  dataIndex: 'equvalue'
              },
              {
                  title: '所在位置',
                  width:300,
                  dataIndex: 'addressS',
                  customRender: (text,record) =>{
                      var ads = record.campusAddress;
                      if(record.buildings){
                          ads+="/"+record.buildings;
                      }
                      if(record.floors){
                          ads+="/"+record.floors;
                      }
                      if(record.rooms){
                          ads+="/"+record.rooms;
                      }
                      if(record.address){
                          ads+=""+record.address;
                      }
                      return ads
                  }
              },
              {
                  title: '启用日期',
                  dataIndex: 'anzDate'
              },
              {
                  title: '状态',
                  dataIndex: 'useState'
              },
              {
                  title: '操作',
                  dataIndex: 'action',
                  align: 'center',
                  width:220,
                  fixed: 'right',
                  scopedSlots: { customRender: 'action' }
              }
          ],
          columns5: [
              {
                  title: '设备名称',
                  dataIndex: 'name',
                  width:200
              },
              {
                  title: '设备小类',
                  dataIndex: 'equType1'
              },
              {
                  title: '型号',
                  dataIndex: 'quality'
              },
              {
                  title: '设备编号',
                  dataIndex: 'equNo',
                  width:150
              },
              {
                  title: '设备原值',
                  dataIndex: 'equvalue'
              },
              {
                  title: '所在位置',
                  width:300,
                  dataIndex: 'addressS',
                  customRender: (text,record) =>{
                      var ads = record.campusAddress;
                      if(record.buildings){
                          ads+="/"+record.buildings;
                      }
                      if(record.floors){
                          ads+="/"+record.floors;
                      }
                      if(record.rooms){
                          ads+="/"+record.rooms;
                      }
                      if(record.address){
                          ads+=""+record.address;
                      }
                      return ads
                  }
              },
              {
                  title: '启用日期',
                  dataIndex: 'anzDate'
              },
              {
                  title: '状态',
                  dataIndex: 'useState'
              },
              {
                  title: '操作',
                  dataIndex: 'action',
                  align: 'center',
                  width:220,
                  fixed: 'right',
                  scopedSlots: { customRender: 'action' }
              }
          ],
          columns6: [
              {
                  title: '设备名称',
                  dataIndex: 'name',
                  width:200
              },
              {
                  title: '设备小类',
                  dataIndex: 'equType1'
              },
              {
                  title: '型号',
                  dataIndex: 'quality'
              },
              {
                  title: '设备编号',
                  dataIndex: 'equNo',
                  width:150
              },
              {
                  title: '设备原值',
                  dataIndex: 'equvalue'
              },
              {
                  title: '所在位置',
                  width:300,
                  dataIndex: 'addressS',
                  customRender: (text,record) =>{
                      var ads = record.campusAddress;
                      if(record.buildings){
                          ads+="/"+record.buildings;
                      }
                      if(record.floors){
                          ads+="/"+record.floors;
                      }
                      if(record.rooms){
                          ads+="/"+record.rooms;
                      }
                      if(record.address){
                          ads+=""+record.address;
                      }
                      return ads
                  }
              },
              {
                  title: '启用日期',
                  dataIndex: 'anzDate'
              },
              {
                  title: '状态',
                  dataIndex: 'useState'
              },
              {
                  title: '操作',
                  dataIndex: 'action',
                  align: 'center',
                  width:220,
                  fixed: 'right',
                  scopedSlots: { customRender: 'action' }
              }
          ],
          columns7: [
              {
                  title: '设备名称',
                  dataIndex: 'name',
                  width:200
              },
              {
                  title: '设备小类',
                  dataIndex: 'equType1'
              },
              {
                  title: '型号',
                  dataIndex: 'quality'
              },
              {
                  title: '设备编号',
                  dataIndex: 'equNo',
                  width:150
              },
              {
                  title: '设备原值',
                  dataIndex: 'equvalue'
              },
              {
                  title: '所在位置',
                  width:300,
                  dataIndex: 'addressS',
                  customRender: (text,record) =>{
                      var ads = record.campusAddress;
                      if(record.buildings){
                          ads+="/"+record.buildings;
                      }
                      if(record.floors){
                          ads+="/"+record.floors;
                      }
                      if(record.rooms){
                          ads+="/"+record.rooms;
                      }
                      if(record.address){
                          ads+=""+record.address;
                      }
                      return ads
                  }
              },
              {
                  title: '启用日期',
                  dataIndex: 'anzDate'
              },
              {
                  title: '状态',
                  dataIndex: 'useState'
              },
              {
                  title: '操作',
                  dataIndex: 'action',
                  align: 'center',
                  width:220,
                  fixed: 'right',
                  scopedSlots: { customRender: 'action' }
              }
          ],
          columns8: [
              {
                  title: '设备名称',
                  dataIndex: 'name',
                  width:200
              },
              {
                  title: '设备小类',
                  dataIndex: 'equType1'
              },
              {
                  title: '型号',
                  dataIndex: 'quality'
              },
              {
                  title: '设备编号',
                  dataIndex: 'equNo',
                  width:150
              },
              {
                  title: '设备原值',
                  dataIndex: 'equvalue'
              },
              {
                  title: '所在位置',
                  width:300,
                  dataIndex: 'addressS',
                  customRender: (text,record) =>{
                      var ads = record.campusAddress;
                      if(record.buildings){
                          ads+="/"+record.buildings;
                      }
                      if(record.floors){
                          ads+="/"+record.floors;
                      }
                      if(record.rooms){
                          ads+="/"+record.rooms;
                      }
                      if(record.address){
                          ads+=""+record.address;
                      }
                      return ads
                  }
              },
              {
                  title: '启用日期',
                  dataIndex: 'anzDate'
              },
              {
                  title: '状态',
                  dataIndex: 'useState'
              },
              {
                  title: '操作',
                  dataIndex: 'action',
                  align: 'center',
                  width:220,
                  fixed: 'right',
                  scopedSlots: { customRender: 'action' }
              }
          ],
          columns9: [
              {
                  title: '设备名称',
                  dataIndex: 'name',
                  width:200
              },
              {
                  title: '设备小类',
                  dataIndex: 'equType1'
              },
              {
                  title: '型号',
                  dataIndex: 'quality'
              },
              {
                  title: '设备编号',
                  dataIndex: 'equNo',
                  width:150
              },
              {
                  title: '设备原值',
                  dataIndex: 'equvalue'
              },
              {
                  title: '所在位置',
                  width:300,
                  dataIndex: 'addressS',
                  customRender: (text,record) =>{
                      var ads = record.campusAddress;
                      if(record.buildings){
                          ads+="/"+record.buildings;
                      }
                      if(record.floors){
                          ads+="/"+record.floors;
                      }
                      if(record.rooms){
                          ads+="/"+record.rooms;
                      }
                      if(record.address){
                          ads+=""+record.address;
                      }
                      return ads
                  }
              },
              {
                  title: '启用日期',
                  dataIndex: 'anzDate'
              },
              {
                  title: '状态',
                  dataIndex: 'useState'
              },
              {
                  title: '操作',
                  dataIndex: 'action',
                  align: 'center',
                  width:220,
                  fixed: 'right',
                  scopedSlots: { customRender: 'action' }
              }
          ],
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
            console.log('loadData.parameter', parameter)
            if(this.roomValue){
                this.queryParam.roomValue = this.roomValue.join(",")
            }
          return postAction(this.url.list, Object.assign(parameter, this.queryParam))
              .then(res => {
                return res.result
              })
        },
          roomValue:[],
          optionsRoom:[],
        selectedRowKeys: [],
        options: {
          alert: {
            clear: () => {
              this.selectedRowKeys = []
            }
          },
          rowSelection: {
            selectedRowKeys: this.selectedRowKeys,
            onChange: this.onSelectChange,
            type: 'checkbox'
          }
        },
        url: {
          list: '/system/equEquipment/list',
            listTree: '/system/devCampusBuildingFloorRoom/listTree',
          delete: '/system/equEquipment/delete'
        }
      }
    },
    computed: {},
      created () {
          this.getRoomListTree()
      },
    methods: {
      // 删除
      handleDelete (record) {
        if (!record) {
          // 如果没有传入，那么批量删除
          record = this.selectedRowKeys.join(',')
        }
        deleteAction(this.url.delete, { ids: record }).then((resp) => {
          this.$message.success('删除成功!')
          this.$refs.table.refresh(true)
        })
      },
        getRoomListTree() {
            getAction(this.url.listTree).then((res) => {
                this.optionsRoom = res.result.data
            })
        },
        init(type){
          if(type.id){
              this.queryParam.equType=type.id
              if(type.id==87){
                  this.columns=this.columns1
              }else if(type.id==88){
                  this.columns=this.columns2
              }else if(type.id==90){
                  this.columns=this.columns3
              }else if(type.id==91){
                  this.columns=this.columns4
              }else if(type.id==92){
                  this.columns=this.columns5
              }else if(type.id==93){
                  this.columns=this.columns6
              }else if(type.id==94){
                  this.columns=this.columns7
              }else if(type.id==95){
                  this.columns=this.columns8
              }else if(type.id==96){
                  this.columns=this.columns9
              }
          }else{
              this.queryParam.equType= undefined
              this.columns=this.columns0
          }
          this.$refs.table.refresh(true)
        },
        rowClick(record, index) {
            return {
                on: {
                    click: () => {

                    },
                    dblclick: () => {
                        this.handelView(record)
                    },
                }
            }
        },
      // 用户编辑
      handleEdit (record) {
        this.$refs.modalEdit.edit(record)
      },
      searchQuery () {
        this.$refs.table.refresh(true)
      },
      // 保存刷新
      modalEditOk () {
        this.$refs.table.refresh()
      },
      // 查看
      handelView (record) {
        this.$refs.modalView.show(record)
      },
      //开启选择
      onSelectChange (selectedRowKeys) {
         console.log('selectedRowKeys changed: ', selectedRowKeys)
         this.selectedRowKeys = selectedRowKeys
      },
        // 值变化处理
        handleChange(value, selectedOptions) {
            console.log(value)
        }
    },
    watch: {}
  }
</script>
<style scoped>
</style>
